﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using University.Workshop.DataAccess;
using System.Data;
using University.Workshop.Model;

namespace University.Workshop.Business
{
    public static class GiftsControl
    {

        public static bool AddGift(string nameGift, string priceGift)
        {
            if (DataAccessGifts.GetGiftByName(nameGift).Rows.Count == 0)
            {
                DataAccessGifts.AddDataGift(nameGift, priceGift);
                return true;
            }
            else {
                throw new BusinessException("Antes de ingresar este premio porfavor elimine el otro con el mismo nombre ");
            }
        }
        public static DataTable GetAllGifts(string gifts)
        {
            DataTable table = DataAccessGifts.GetAllGifts(gifts);
           
            return table;
        }
        public static void DeleteGift(string name)
        {
            DataAccessGifts.DeleteGiftByName(name);
        }

        public static string GetGiftByPricesAndClient(string nit, string amount)
        {
            double newMount = ClientDataAccess.GetTotalMountForClient(nit);
            double lastMount = newMount - Convert.ToDouble( amount,System.Globalization.CultureInfo.CurrentCulture);
            DataColumn dc = DataAccessGifts.GetGiftByPrices(lastMount, newMount);
            string resp=string.Empty;
            if (dc.Table.Rows.Count != 0)
            {
                resp = "Los premios que puede elejir el cliente por su compra son: ";
                foreach (DataRow dr in dc.Table.Rows)
                {
                    resp += dr.ItemArray[0]+", ";
                }
            }
            if (dc != null) {
                dc.Dispose();
            }
            return resp;
        }
    }
}
